package day02_homework;

import java.util.Scanner;

public class Test01 {
    public static void main(String[] args) {
        String str = "abc123def456";
        System.out.println(str.matches("[0-9]+"));

        String str1 = "abc123def456";
        System.out.println(str1.matches("[a-zA-Z0-9_]{3,15}"));

        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入用户名");
            String username = sc.nextLine();
            if (username.matches("[a-zA-Z0-9_]{3,15}")) {
                System.out.println("用户名正确");
                while (true) {
                    System.out.println("请输入年龄");
                    String age = sc.nextLine();
                    if (age.matches("\\d+")) {
                        int age1 = Integer.parseInt(age);//age类型转换
                        if (age1 >= 1 && age1 <= 100) {
                            System.out.println("年龄正确");
                            break;
                        } else {
                            System.out.println("年龄有误");
                        }
                    } else {
                        System.out.println("年龄有误");
                    }
                }
                break;
            } else {
                System.out.println("用户名有误");
            }
        }

    }
}
